<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Member extends Common
{
    public function index()
    {

    }
	/*
	 *会员信息列表
	 */
	public function m_list(){
		$id = Request::instance()->Param();
		if(!empty($id)){
			$data = Db::table('member')->where($id) -> paginate(10);
			$this -> assign('data',$data);
			$this -> assign('check',1);
			return $this -> fetch();
		}

		$data = Db::table('member')-> where('member_check',2) -> paginate(10);
		$this -> assign('data',$data);
		return $this -> fetch();
	}
	/*
	 *添加会员信息
	 */
	public function m_add(){
		$data = Request::instance()->Param();
		$res = '';
		if(!empty($data)){
			$res = Db::table('member') -> where($data) -> find();
		}
		$this -> assign('res',$res);
		return $this -> fetch();
	}
	/*
	 *添加会员操作
	 */
	public function doM_add(){
		$data = Request::instance()->Param();
		$ip = $_SERVER["REMOTE_ADDR"];
		$data['member_ip'] = $ip;
		$data['member_date'] = time();
		$data['member_pass'] = md5($data['member_pass']);
		// 获取表单上传文件 例如上传了001.jpg
		$file = request()-> file('member_avatar');
		$info = $file->move(ROOT_PATH  . 'public'.DS. 'uploads'.DS.'managers');
		if($info){
			$photo =  '/uploads/member/'.$info->getSaveName();
		}else{
			$this->error('图片上传失败');
		}
		$data['member_avatar'] = $photo;
		$result = Db::table('member') -> insert($data);
		if($result){
			//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
			$this->success('新增成功', 'Member/m_list');
        } else {
			//错误页面的默认跳转页面是返回前一页，通常不需要设置
			$this->error('新增失败');
		}
	}
	/*
	 *删除会员信息
	 */
	public function M_delete(){
		$data = Request::instance()->Param();
		$result = Db::table('member') -> where($data) -> delete();
		if($result){
			//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
			$this->success('删除成功', 'Administrator/managersList');
        } else {
			//错误页面的默认跳转页面是返回前一页，通常不需要设置
			$this->error('删除失败');
		}
	}
	/*
	 *查看会员信息
	 */
	public function m_select(){
		$data = Request::instance()->Param();
		$res = '';
		if(!empty($data)){
			$res = Db::table('member') -> where($data) -> find();
		}
		$this -> assign('res',$res);
		return $this -> fetch();
	}
	/*
	 *审核会员操作
	 */
	public function m_check(){
		$data = Request::instance()->Param();
		$result = Db::table('member') -> where($data) -> update(array('member_check' => 2,'member_status' => 1));
		if($result){
			//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
			$this->success('审核成功', 'Member/m_list');
        } else {
			//错误页面的默认跳转页面是返回前一页，通常不需要设置
			$this->error('审核失败');
		}
	}
}
